package daemon;

import java.io.File;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 * Comparator class used to compare packages' IDs.
 * e.g. "4.5"  < "4.6", "4.5" > "3.9"
 */
public class PackagesSort implements Comparator<File> {
	    @Override
	    public int compare(File f1, File f2) {
	    	StringTokenizer st = new StringTokenizer(f1.getName(), ".");
	    	int c1 = Integer.parseInt(st.nextToken());
	    	int m1 = Integer.parseInt(st.nextToken());
	    	st = new StringTokenizer(f2.getName(), ".");
	    	int c2 = Integer.parseInt(st.nextToken());
	    	int m2 = Integer.parseInt(st.nextToken());
	    	if(c1>c2)
	    			return 1;
	    	if(c1<c2)
	    			return -1;
	    	if(m1>m2)
	    			return 1;
	    	if(m1<m2)
	    			return -1;
	    	return 0;
	    	
	    }
}
